package com.ahtcm.tcmlearning.controller;

import com.ahtcm.tcmlearning.dataObject.brushProblem.QuestionToShow;
import com.ahtcm.tcmlearning.dataObject.brushProblem.RateOfLearning;
import com.ahtcm.tcmlearning.dataObject.brushProblem.SubjectChapterParent;
import com.ahtcm.tcmlearning.exception.ResultEnum;
import com.ahtcm.tcmlearning.model.Question;
import com.ahtcm.tcmlearning.service.BrushProblemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yangrongdeng
 * @descriptionn 刷题模块
 * @date 2019.01.06
 */
@RestController
@RequestMapping("/brushProblem")
public class BrushProblemController {

    @Autowired
    private BrushProblemService brushProblemService;

   /**
     *
     * @param subjectId
     * @description 按学科返回章节内容
     */
    @GetMapping("subjectChapterList")
    public List<SubjectChapterParent> subjectChapterList(@RequestParam("subjectId") Integer subjectId) {
        return brushProblemService.subjectChapterList(subjectId);

    }

    /**
     * @param userId
     * @param categoryId
     * @description 通过提供的类目，从数据库拿出题目
     */
    @GetMapping("findQuestionByCategory")
    public List<QuestionToShow> findQuestionByCategory(@RequestParam("userId") Integer userId, @RequestParam("categoryId") Integer categoryId) {
        List<QuestionToShow> list = brushProblemService.findQuestionByCategory(userId, categoryId);
        return list;
    }

    /**
     * @param questionType 功能模块标识，0章节刷题功能模块用户添加的做题记录,1记忆斩中药模块添加的种类记录,2记忆斩方剂模块添加的种类记录
     * @param userId       用户ID
     * @param categoryId   题目内容的类别id
     * @param questionId   问题的id
     * @param isRight      是否正确
     * @description 已做题目结果加载到做题记录表中
     */
    @GetMapping("addQuestionResultRecord")
    public Integer addQuestionResultRecord(@RequestParam("questionType") Integer questionType, @RequestParam("userId") Integer userId, @RequestParam("categoryId") Integer categoryId, @RequestParam("questionId") Integer questionId, @RequestParam("isRight") Integer isRight) throws Exception {
        try {
            brushProblemService.addQuestionRecord(questionType, userId, categoryId, questionId, isRight);
            return ResultEnum.SUCCESS.getCode();
        } catch (Exception e) {
            throw new Exception(ResultEnum.ADD_ERROR.getMsg());

        }
    }

    /**
     * @param targetId       要收藏的目标id
     * @param userId         用户id
     * @param collectionType 收藏的类型,2为题目，0为药材,1为方剂
     * @param dicId          所属类型，如:某题目属于麻黄汤
     * @description 收藏题目
     */
    @GetMapping("collectionQuestion")
    public Integer collectionQuestion(@RequestParam("targetId") Integer targetId, @RequestParam("userId") Integer userId, @RequestParam("collectionType") Integer collectionType, @RequestParam("dicId") Integer dicId) throws Exception {
        try {
            brushProblemService.collectionQuestion(targetId, userId, collectionType, dicId);
            return ResultEnum.SUCCESS.getCode();
        } catch (Exception e) {
            throw new Exception(ResultEnum.COLLECTION_ERROR.getMsg());
        }

    }
//......................................................................记忆斩模块..................................................
//1, "记忆斩中药模块添加的种类记录"  2, "记忆斩方剂模块添加的种类记录" 3, "记忆斩针灸学模块添加的种类记录"  4, "记忆斩药鉴定模块添加的种类记录" 5, "记忆斩病理学模块添加的种类记录"
//
//    /**
//     * @description 获得记忆斩某模块的学习进度
//     * @param functionType
//     * @param userId
//     * @return
//     */
//    @GetMapping("getRateOfLearning")
//    public RateOfLearning getRateOfLearning(@RequestParam("functionType") Integer functionType, @RequestParam("userId") Integer userId) {
//        RateOfLearning rateOfLearning = brushProblemService.getRateOfLearning(functionType, userId);
//        return rateOfLearning;
//    }


//   @GetMapping("getKnowledgePointDetail")
//   public Object getKnowledgePointDetail(@RequestParam("functionType") Integer functionType, @RequestParam("userId") Integer userId){
//    Object  knowledgePoint= brushProblemService.getKnowledgePointDetail(functionType,userId);
//    return knowledgePoint;
//   }
//
//
//    /**
//     * @param functionType 功能模块类型标识
//     * @param userId       用户ID
//     * @param categoryId   题目内容的类别id
//     * @description 记录记忆斩功能用户已经生成过题目的药材
//     */
//    @GetMapping("recordGenerateCategory")
//    public void recordGenerateCategory(@RequestParam("functionType") Integer functionType, @RequestParam("userId") Integer userId, @RequestParam("categoryId") Integer categoryId) {
//        brushProblemService.addQuestionRecord(functionType, userId, categoryId, null, null);
//    }

}